package com.wang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Classname SwaggerConfig
 * @Description TODO
 * @Date 2024/8/29 11:06
 * @Created by pc
 */
@Configuration
@EnableSwagger2
@EnableWebMvc  // springboot 2.6.5 以上的版本就需要加这个
public class SwaggerConfig {

    // 向IOC容器中注册Docket
    @Bean
    public Docket apiDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.wang.controller.api"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("前台控制器");
    }
    @Bean
    public Docket adminDocket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .apis(RequestHandlerSelectors.basePackage("com.wang.controller.admin"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo())
                .groupName("后台控制器");
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("333电商项目接口文档")
                .description("333电商项目接口文档测试")
                .version("0.0.1")
                .contact(new Contact("wang","https://www.wang.com","446470238@qq.com"))
                .termsOfServiceUrl("")
                .license("")
                .build();
    }
}
